package org.otherworld.frame.filebrowser;


import java.awt.BorderLayout;
import java.io.File;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.border.EmptyBorder;


import org.otherworld.frame.filebrowser.tree.FileTreeCellRenderer;
import org.otherworld.frame.filebrowser.tree.FileTreeNode;

public class FilePanel extends JPanel{
	private static final long serialVersionUID = 1L;	
	private String name;
	private JFrame ancestor;
	private JPanel panel;
	private String componentName;
	private JTree tree;
	
	public FilePanel(JFrame ancestor,JPanel panel) {
		this.ancestor = ancestor;
		this.panel = panel;
	}
	
	
	
	public void setTreeName(String name) {
		this.name = name;
	}
	
	public void setComponentName(String name) {
		this.componentName = name;
	}
	
	public void renderTree() {
		this.setLayout(new BorderLayout());
		File[] roots = File.listRoots();
		FileTreeNode rootNodes = new FileTreeNode(roots);
		tree = new JTree(rootNodes);
		tree.setCellRenderer(new FileTreeCellRenderer());
		tree.setRootVisible(false);
		tree.addMouseListener(new TreeMouseAdapter(ancestor,panel));
		tree.setName(name);

		final JScrollPane jsp = new JScrollPane(tree);
		jsp.setBorder(new EmptyBorder(0, 0, 0, 0));
		this.add(jsp);
	}
	
	public JTree getTree() {
		return this.tree;
	}
	



	
}
